package com.watermeter.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.watermeter.android.R;
import com.watermeter.android.entry.CrutorJlu;

import java.util.List;

/**
 * 客户查询
 * Created by zouqh on 2016/5/23.
 */
public class CurstorAdapter extends BaseAdapter {
    private Context context;
    private List<CrutorJlu> rowses;

    public CurstorAdapter(Context context, List<CrutorJlu> rowses) {
        this.context = context;
        this.rowses = rowses;
    }

    @Override
    public int getCount() {
        return rowses.size();
    }

    @Override
    public Object getItem(int position) {
        return rowses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler;
        if (convertView == null) {
            viewHodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.crutor_item, null);
            viewHodler.ysyf = (TextView) convertView.findViewById(R.id.ysyf);
            viewHodler.name = (TextView) convertView.findViewById(R.id.name);
            viewHodler.cbrq = (TextView) convertView.findViewById(R.id.cbrq);
            viewHodler.byds = (TextView) convertView.findViewById(R.id.byds);

            viewHodler.bjsl = (TextView) convertView.findViewById(R.id.bjsl);
            viewHodler.byyl = (TextView) convertView.findViewById(R.id.byyl);
            viewHodler.sf = (TextView) convertView.findViewById(R.id.sf);
            viewHodler.jyf = (TextView) convertView.findViewById(R.id.jyf);
            viewHodler.wsf = (TextView) convertView.findViewById(R.id.wsf);
            viewHodler.fyhj = (TextView) convertView.findViewById(R.id.fyhj);
            viewHodler.qfje = (TextView) convertView.findViewById(R.id.qfje);
            viewHodler.syds = (TextView) convertView.findViewById(R.id.syds);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }

        viewHodler.name.setText("客户名称：" + rowses.get(position).getUSERNAME());
        viewHodler.ysyf.setText("用水月份：" + rowses.get(position).getSMON());
        String rq=rowses.get(position).getLASTUPDT();
        viewHodler.cbrq.setText("抄表日期：" + rq.substring(0,10));
        viewHodler.byds.setText("本月读数：" + rowses.get(position).getBYDS());
        viewHodler.syds.setText("上月读数：" + rowses.get(position).getSYDS());
        viewHodler.bjsl.setText("标记水量：" + rowses.get(position).getBJSL()+" t");
        viewHodler.byyl.setText("本月用量：" + rowses.get(position).getBYYL()+" t");
        viewHodler.sf.setText("水费：" + rowses.get(position).getSF());

        viewHodler.jyf.setText("加压费：" + rowses.get(position).getJYF());
        viewHodler.wsf.setText("污水费：" + rowses.get(position).getWSCLF());
        viewHodler.fyhj.setText("费用合计：" + rowses.get(position).getHJ());
        viewHodler.qfje.setText("欠费金额：" + rowses.get(position).getHASBILL());
        return convertView;
    }

    class ViewHodler {
        TextView name;
        TextView ysyf;
        TextView cbrq;
        TextView byds;
        TextView bjsl;
        TextView byyl;
        TextView sf;
        TextView jyf;
        TextView wsf;
        TextView fyhj;
        TextView qfje;
        TextView syds;
    }
}
